/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2008                    */
/* Created on:     8/5/2012 6:57:16 PM                          */
/*==============================================================*/


if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('TInfoRelease_Info') and o.name = 'FK_TINFOREL_REFERENCE_TINFOREL')
alter table TInfoRelease_Info
   drop constraint FK_TINFOREL_REFERENCE_TINFOREL
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('TSys_Log') and o.name = 'FK_TSYS_LOG_REFERENCE_TSYS_USE')
alter table TSys_Log
   drop constraint FK_TSYS_LOG_REFERENCE_TSYS_USE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('TSys_Re_Role_User') and o.name = 'FK_TSYS_RE__REFERENCE_TSYS_ROL')
alter table TSys_Re_Role_User
   drop constraint FK_TSYS_RE__REFERENCE_TSYS_ROL
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('TSys_Re_Role_User') and o.name = 'FK_TSYS_RE__REFERENCE_TSYS_USE')
alter table TSys_Re_Role_User
   drop constraint FK_TSYS_RE__REFERENCE_TSYS_USE
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TInfoRelease_Info')
            and   type = 'U')
   drop table TInfoRelease_Info
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TInfoRelease_Item')
            and   type = 'U')
   drop table TInfoRelease_Item
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TIni_CodeMode')
            and   type = 'U')
   drop table TIni_CodeMode
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TSys_Log')
            and   type = 'U')
   drop table TSys_Log
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TSys_Re_Role_User')
            and   type = 'U')
   drop table TSys_Re_Role_User
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TSys_Role')
            and   type = 'U')
   drop table TSys_Role
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TSys_User')
            and   type = 'U')
   drop table TSys_User
go

/*==============================================================*/
/* Table: TInfoRelease_Info                                     */
/*==============================================================*/
create table TInfoRelease_Info (
   InfoID               int                  identity,
   ItemID               int                  not null,
   InfoIcon             nvarchar(80)         null,
   InfoTitle            nvarchar(50)         null,
   InfoBody             ntext                null,
   InfoAuthor           nvarchar(20)         null,
   InfoOrigin           nvarchar(80)         null,
   InfoKeyword          nvarchar(20)         null,
   Creator              int                  null,
   CreatedDate          datetime             null,
   Modifier             int                  null,
   ModifiedDate         datetime             null,
   constraint PK_TINFORELEASE_INFO primary key (InfoID, ItemID)
)
go

/*==============================================================*/
/* Table: TInfoRelease_Item                                     */
/*==============================================================*/
create table TInfoRelease_Item (
   ItemID               int                  identity,
   PItemID              int                  null,
   Level                int                  null,
   ItemName             nvarchar(20)         null,
   ItemDesc             nvarchar(200)        null,
   ItemSort             int                  null,
   LinkURL              nvarchar(80)         null,
   Active               bit                  null,
   constraint PK_TINFORELEASE_ITEM primary key nonclustered (ItemID)
)
go

/*==============================================================*/
/* Table: TIni_CodeMode                                         */
/*==============================================================*/
create table TIni_CodeMode (
   CodeModeID           int                  identity,
   CodeType             nvarchar(20)         not null,
   CodeModeAlia         nvarchar(10)         not null,
   CodeName             nvarchar(20)         null,
   CodeSample           nvarchar(50)         null,
   Active               bit                  null,
   constraint PK_TINI_CODEMODE primary key nonclustered (CodeModeID, CodeType, CodeModeAlia)
)
go

/*==============================================================*/
/* Table: TSys_Log                                              */
/*==============================================================*/
create table TSys_Log (
   LogID                int                  identity,
   ActionContent        nvarchar(200)        null,
   OperatorID           int                  null,
   AccessTime           datetime             null,
   constraint PK_TSYS_LOG primary key (LogID)
)
go

/*==============================================================*/
/* Table: TSys_Re_Role_User                                     */
/*==============================================================*/
create table TSys_Re_Role_User (
   RoleID               int                  not null,
   UserID               int                  not null,
   constraint PK_TSYS_RE_ROLE_USER primary key (RoleID, UserID)
)
go

/*==============================================================*/
/* Table: TSys_Role                                             */
/*==============================================================*/
create table TSys_Role (
   RoleID               int                  identity,
   PRoleID              int                  null,
   Level                int                  null,
   RoleCode             nvarchar(20)         null,
   RoleName             nvarchar(50)         null,
   Description          nvarchar(200)        null,
   Active               bit                  null,
   constraint PK_TSYS_ROLE primary key (RoleID)
)
go

/*==============================================================*/
/* Table: TSys_User                                             */
/*==============================================================*/
create table TSys_User (
   UserID               int                  identity,
   Account              nvarchar(20)         null,
   Password             nvarchar(80)         null,
   RealName             nvarchar(20)         null,
   Mobile               nvarchar(20)         null,
   eMail                nvarchar(20)         null,
   Description          nvarchar(200)        null,
   LastLoginTime        datetime             null,
   Active               bit                  null,
   constraint PK_TSYS_USER primary key (UserID)
)
go

alter table TInfoRelease_Info
   add constraint FK_TINFOREL_REFERENCE_TINFOREL foreign key (ItemID)
      references TInfoRelease_Item (ItemID)
go

alter table TSys_Log
   add constraint FK_TSYS_LOG_REFERENCE_TSYS_USE foreign key (OperatorID)
      references TSys_User (UserID)
go

alter table TSys_Re_Role_User
   add constraint FK_TSYS_RE__REFERENCE_TSYS_ROL foreign key (RoleID)
      references TSys_Role (RoleID)
go

alter table TSys_Re_Role_User
   add constraint FK_TSYS_RE__REFERENCE_TSYS_USE foreign key (UserID)
      references TSys_User (UserID)
go

